package com.info33.platform.business.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.info33.platform.business.app.dao.AppFeedbackDao;
import com.info33.platform.business.app.dto.AppFeedbackDTO;
import com.info33.platform.business.app.entity.AppFeedback;
import com.info33.platform.business.app.service.AppFeedbackService;
import com.info33.platform.common.constant.TableConstant;
import com.info33.platform.system.vo.SysUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * @author admin
 */
@Service
public class AppFeedbackServiceImpl extends ServiceImpl<AppFeedbackDao, AppFeedback> implements AppFeedbackService {

    @Autowired
    private AppFeedbackDao appFeedbackDao;

    @Override
    public IPage<AppFeedback> appMyHistory(Page<AppFeedback> page, AppFeedbackDTO dto, SysUserVO currentUser) {
        QueryWrapper<AppFeedback> qw = new QueryWrapper<>();
        if (StringUtils.hasText(dto.getContent())) {
            qw.like("content", dto.getContent());
        }
        if (!ObjectUtils.isEmpty(dto.getType())) {
            qw.eq("type", dto.getType());
        }
        qw.eq(TableConstant.CREATE_BY, currentUser.getAppTenantUserVO().getId())
                .orderByDesc(TableConstant.CREATE_DATE);
        return this.page(page, qw);
    }

}